# -*- coding: utf-8 -*-
import socket
import threading

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('0.0.0.0', 8000))
server.listen()


'''
data = sock.recv(1024)
print(data.decode("utf8"))
sock.send("hello {} from server".format(data.decode("utf8")).encode("utf8"))
server.close()
sock.close()
'''


def sock_handle(_sock, addr):
    while True:
        data = _sock.recv(1024)
        print(data.decode("utf8"))
        re_data = input('>> ')
        _sock.send(re_data.encode("utf8"))


while True:
    sock, addr = server.accept()
    client_thread = threading.Thread(target=sock_handle, args=(sock, addr))
    client_thread.start()